package com.weipai.demo.controller;

import com.weipai.demo.enums.RetCode;
import com.weipai.demo.model.CarBrand;
import com.weipai.demo.model.CarContent;
import com.weipai.demo.model.VehicleModel;
import com.weipai.demo.service.CarPriceService;
import com.weipai.demo.util.LayuiTablePagingResult;
import com.weipai.demo.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/25 14:59
 * @Version 1.0
 */
@RestController
public class CarPriceController {

    @Autowired
    private CarPriceService carPriceService;

    //三级列表展示
    @RequestMapping(value = "/getCarCategory/list")
    public Response getCarCategory(Integer sign) {
        return carPriceService.getCarCategory(sign);
    }

    //添加或修改品牌
    @RequestMapping(value = "/handleCarCategory/info")
    public Response handleCarCategory(CarBrand carBrand) {
        return carPriceService.handleCarCategory(carBrand);
    }

    //删除品牌
    @RequestMapping(value = "/delCarCategory/info")
    public Response delCarCategory(Integer id) {
        return carPriceService.delCarCategory(id);
    }

    //添加价格等信息
    @RequestMapping(value = "/add/CarInfomation")
    public Response addCarInfomation(CarContent carContent) {
        return carPriceService.addCarContent(carContent);
    }

    //右边的列表
    @RequestMapping(value = "/car/getCarInfomationList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public LayuiTablePagingResult getCarInfomationList(Integer bid, Integer tid, Integer pid, Integer page, Integer size) {
        return carPriceService.getCarInfomationList(bid, tid, pid, page, size);
    }

    //删除右边的列表
    @RequestMapping(value = "/car/delCarInfomationList")
    public Response delCarInfomationList(Integer id) {
        return carPriceService.delCarInfomationList(id);
    }


    //车贷信息的添加
    @RequestMapping(value = "/car/save")
    public Response save(VehicleModel vehicleModel, HttpServletRequest request) {
        Response response = new Response();
        HttpSession session = request.getSession();
        String code = request.getParameter("code");
        String sessionQrcode = (String) session.getAttribute("code" + code);
        if(sessionQrcode == null){
            response.setCode(RetCode.ERRORCODE);
            return response;
        }
        if (sessionQrcode.toLowerCase().equals(request.getParameter("qrcode").toLowerCase())) {
            return carPriceService.save(vehicleModel);
        } else {
            response.setCode(RetCode.ERRORCODE);
            return response;
        }
    }

    //车贷信息的添加
    @RequestMapping(value = "/vehicle/showApplyfor")
    public Response showApplyfor(Integer page, Integer size) {
        return carPriceService.showApplyfor(page, size);
    }

    //车贷信息的删除
    @RequestMapping(value = "/vehicle/delApplyfor")
    public Response delApplyfor(Integer id) {
        return carPriceService.delApplyfor(id);
    }


    //==================================================================================================================

    //汽车品牌的修改
    @RequestMapping(value = "car/updateBrand")
    public Response update(Integer id, String brand, String type) {
        return carPriceService.update(id, brand, type);
    }

    //汽车型号的修改
    @RequestMapping(value = "car/updateModel")
    public Response updateModel(Integer id, String vehicleModel, String type) {
        return carPriceService.updateModel(id, vehicleModel, type);
    }

    //车型参数的修改
    @RequestMapping(value = "/car/updateParameter")
    public Response updateParameter(Integer id, String parameter, String referencePrice, String type) {
        return carPriceService.updateParameter(id, parameter, referencePrice, type);
    }


    //==================================================================================================================

    //前端页面车贷信息显示
    @RequestMapping(value = "/car/frontShow")
    public Response frontShow(String display, String brand, String vehicleModel, String type) {
        return carPriceService.frontShow(display, brand, vehicleModel, type);
    }


    //==================================================================================================================


    //后台显示车贷信息
   /* @RequestMapping(value = "/car/pageShow")
    public LayuiTablePagingResult pageShow(Integer page, Integer size, String display){
        return carPriceService.pageShow(page,size,display);
    }*/

    //==================================================================================================================


    //删除汽车品牌
    @RequestMapping(value = "/car/deleteById")
    public Response deleteById(Integer id) {
        return carPriceService.deleteById(id);
    }


}
